package com.ruoyi.hr.controller.hr.welfare.welfarebaseadjustment;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.welfare.welfarebaseadjustment.SocialSecurityBaseAdjustmentService;
import com.ruoyi.hr.util.BaseResult;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 社保基数调整
 * @date 2020/1/6 13:56
 */
@Controller
@RequestMapping("/welfare/welfarebaseadjustment/socialsecuritybaseadjustment")
public class SocialSecurityBaseAdjustmentController extends BaseController {

    @Autowired
    private SocialSecurityBaseAdjustmentService socialSecurityBaseAdjustmentService;

    @Autowired
    AuthorityService authorityService;


    private String prefix = "hr/welfare/welfarebaseadjustment/socialsecuritybaseadjustment";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String welfarebaseadjustment() {
        return prefix + "/socialSecurityBaseAdjustment";
    }

    /**
     * 新增跳转
     *
     * @return
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增人员存储过程
     */
    @PostMapping("/addbeneChangeSocialAdd")
    @ResponseBody
    public BaseResult addbeneChangeSocialAdd(String allPeid) {
        return socialSecurityBaseAdjustmentService.addbeneChangeSocialAdd(allPeid);
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String, Object>> list = socialSecurityBaseAdjustmentService.findData(map,authorityList,isAdmin);
        return getDataTable(list);
    }

    /**
     * 修改跳转
     *
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") int id, ModelMap mmap) {
        //获取单个数据
        mmap.put("socialSecurityBaseAdjustment", socialSecurityBaseAdjustmentService.findDataById(id + ""));
        return prefix + "/edit";
    }

    /**
     * 删除员工 确认检查 取消确认 处理生效存储过程调用
     */
    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String procedure) {
        return socialSecurityBaseAdjustmentService.procedure(allId, procedure);
    }

    /**
     * 修改操作
     *
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map<String, String> map) {
        return toAjax(socialSecurityBaseAdjustmentService.updateSocialSecurityBase(map));
    }
}
